package com.sponsorpay.sdk.android.publisher;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslCertificate.DName;
import android.net.http.SslError;
import android.view.WindowManager.BadTokenException;
import android.webkit.SslErrorHandler;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.sponsorpay.sdk.android.utils.IntentHelper;
import com.sponsorpay.sdk.android.utils.SponsorPayLogger;
import java.lang.ref.WeakReference;

public abstract class OfferWebClient extends WebViewClient
{
  private static final String EXIT_URL_RESULT_CODE_PARAM_KEY = "status";
  private static final String EXIT_URL_TARGET_URL_PARAM_KEY = "url";
  public static final String LOG_TAG = "OfferWebClient";
  public static final int RESULT_CODE_NO_STATUS_CODE = -10;
  private static final String SPONSORPAY_EXIT_SCHEMA = "exit";
  private static final String SPONSORPAY_SCHEMA = "sponsorpay://";
  private WeakReference<Activity> mHostActivityRef;

  public OfferWebClient(Activity paramActivity)
  {
    this.mHostActivityRef = new WeakReference(paramActivity);
  }

  protected Activity getHostActivity()
  {
    return (Activity)this.mHostActivityRef.get();
  }

  protected boolean launchActivityWithUrl(String paramString)
  {
    Activity localActivity = getHostActivity();
    if (localActivity == null);
    Uri localUri;
    do
    {
      do
        return false;
      while (paramString == null);
      Intent localIntent = new Intent();
      localIntent.setAction("android.intent.action.VIEW");
      localUri = Uri.parse(paramString);
      localIntent.setData(localUri);
      try
      {
        localActivity.startActivity(localIntent);
        onTargetActivityStart(paramString);
        return true;
      }
      catch (ActivityNotFoundException localActivityNotFoundException)
      {
      }
    }
    while ((!localUri.getScheme().equalsIgnoreCase("market")) || (IntentHelper.isIntentAvailable(getHostActivity(), "android.intent.action.VIEW", Uri.parse("market://search?q=pname:com.google"))));
    SponsorPayLogger.e("OfferWebClient", "Play Store is not installed on this device...");
    onPlayStoreNotFound();
    return false;
  }

  protected void onPlayStoreNotFound()
  {
    showDialog(SponsorPayPublisher.getUIString(SponsorPayPublisher.UIStringIdentifier.ERROR_PLAY_STORE_UNAVAILABLE));
  }

  public void onReceivedSslError(WebView paramWebView, SslErrorHandler paramSslErrorHandler, SslError paramSslError)
  {
    if (paramSslError.getCertificate().getIssuedBy().getOName().matches(".*StartCom Ltd.*"))
      paramSslErrorHandler.proceed();
  }

  protected abstract void onSponsorPayExitScheme(int paramInt, String paramString);

  protected abstract void onTargetActivityStart(String paramString);

  protected int parseSponsorPayExitUrlForResultCode(String paramString)
  {
    String str = Uri.parse(paramString).getQueryParameter("status");
    if (str != null)
      return Integer.parseInt(str);
    return -10;
  }

  protected String parseSponsorPayExitUrlForTargetUrl(String paramString)
  {
    return Uri.parse(paramString).getQueryParameter("url");
  }

  protected abstract void processSponsorPayScheme(String paramString, Uri paramUri);

  public boolean shouldOverrideUrlLoading(WebView paramWebView, String paramString)
  {
    SponsorPayLogger.i("OfferWebClient", "shouldOverrideUrlLoading called with url: " + paramString);
    if (paramString.startsWith("sponsorpay://"))
    {
      Uri localUri = Uri.parse(paramString);
      String str1 = localUri.getHost();
      if (str1.equals("exit"))
      {
        int i = parseSponsorPayExitUrlForResultCode(paramString);
        String str2 = parseSponsorPayExitUrlForTargetUrl(paramString);
        SponsorPayLogger.i("OfferWebClient", "Overriding. Target Url: " + str2);
        onSponsorPayExitScheme(i, str2);
      }
      while (true)
      {
        return true;
        processSponsorPayScheme(str1, localUri);
      }
    }
    SponsorPayLogger.i("OfferWebClient", "Not overriding");
    return false;
  }

  public void showDialog(String paramString)
  {
    String str1 = SponsorPayPublisher.getUIString(SponsorPayPublisher.UIStringIdentifier.ERROR_DIALOG_TITLE);
    String str2 = SponsorPayPublisher.getUIString(SponsorPayPublisher.UIStringIdentifier.DISMISS_ERROR_DIALOG);
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(getHostActivity());
    localBuilder.setTitle(str1);
    localBuilder.setMessage(paramString);
    localBuilder.setNegativeButton(str2, new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        paramAnonymousDialogInterface.dismiss();
      }
    });
    AlertDialog localAlertDialog = localBuilder.create();
    localAlertDialog.setOwnerActivity(getHostActivity());
    try
    {
      localAlertDialog.show();
      return;
    }
    catch (WindowManager.BadTokenException localBadTokenException)
    {
      SponsorPayLogger.e(getClass().getSimpleName(), "Couldn't show error dialog. Not displayed error message is: " + paramString, localBadTokenException);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.sponsorpay.sdk.android.publisher.OfferWebClient
 * JD-Core Version:    0.6.2
 */